<template>
	<view class="box">
		<view class="top">
			<u-navbar :is-back="true" title="我的收藏" :border-bottom="false"></u-navbar>
		</view>
		<view class="clear" style="text-align: right; font-size: 40rpx; font-weight: bold; width: 750rpx; box-sizing: border-box; padding: 20rpx;" @click="cancelBtn">
			清除足迹
		</view>
		<view class="collect " v-if="collect.length>0">
			<view class="item container_br jsbc" v-for="item in collect" :key="item.id">
				<view class="left">
					<image :src="item.goods.images_format[0]" mode="widthFix" style="width: 150rpx;"></image>
				</view>
				<view class="right">
					<view class="name">
						{{item.goods.name}}
					</view>
					<view class="price" style="color: red;">
						￥{{item.goods.min_price}}
					</view>
					<view class="time">
						收藏时间：{{item.updated_at}}
					</view>
				</view>
			</view>
		</view>
		<view class="noData" style="width: 410rpx; height: 240rpx ;margin: 40rpx auto;" v-else>
			<image src="../../static/img/empty.png" mode="widthFix" style="width: 410rpx; height: 240rpx;"></image>
		</view>
	</view>
</template>

<script>
	import {
		getzj,
		clearzj
	} from '@/api/index.js'

	import {
		getCollect,
		cancelCollect
	} from '@/api/index.js'
	import {
		closeload,
		toast,
		toastload
	} from '@/utils/common.js'
	import baseUrl from '@/config/config.js'
	export default {
		data() {
			return {
				user_id: "",
				collect: []
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				toastload()
				getzj().then(res => {
					console.log("我的收藏", res);
					closeload()
					this.collect = res.list

				})
			},
			cancelBtn(id) {
				let slef = this
				uni.showModal({
					title:"是否清除",
					success(res) {
						if(res.confirm){
							toastload()
							clearzj().then(res => {
								closeload()
								if (res.code == 200) {
									setTimeout(()=>{
										toast("清除成功")
										self.init()
									},300)
								}
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.collect {
		width: 710rpx;
		margin: 20rpx auto;
		box-sizing: border-box;
		padding: 1rpx;
	}

	.item {
		.left {
			width: 150rpx;
			height: 150rpx;
			overflow: hidden;
			border-radius: 20rpx;
		}

		.right {
			width: 480rpx;
			height: 150rpx;
			box-sizing: border-box;
			padding: 10rpx 0;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.time {
				font-size: 26rpx;
				color: #666;
			}
		}
	}
</style>